﻿using Mogre;
using ObjCore.MOgreExt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObjCore.Interface
{
    public static class ILoaderExt
    {
        public static AxisAlignedBox CalcBox(this ILoader l)
        {
            AxisAlignedBox box = new AxisAlignedBox();

            var dots = l.V;
            var bmin = dots[0];
            var bmax = dots[0];
            foreach (var d in dots)
            {
                bmin.x = System.Math.Min(bmin.x, d.x);
                bmin.y = System.Math.Min(bmin.y, d.y);
                bmin.z = System.Math.Min(bmin.z, d.z);

                bmax.x = System.Math.Max(bmax.x, d.x);
                bmax.y = System.Math.Max(bmax.y, d.y);
                bmax.z = System.Math.Max(bmax.z, d.z);
            }

            box.SetMinimum(bmin);
            box.SetMaximum(bmax);

            return box;
        }
    }
}
